import os

from flask import Flask, session, request

app = Flask(__name__)
# 启用session
app.config['SECRET_KEY'] = os.urandom(24)


@app.route('/login')
def login():
    session['isLogin'] = True
    return '登录成功'


@app.route('/update_user')
def update_user():
    return '修改用户信息成功'


@app.before_request
def before():
    url = request.path

    pass_path = ['/', '/login', '/reg']
    suffix = url.endswith('png') or url.endswith('jpg') or url.endswith('css')

    if url in pass_path or suffix:
        pass
    else:
        ifLogin = session.get('isLogin')
        if not ifLogin:
            return '请登录'


if __name__ == '__main__':
    app.run(debug=True)
